package cn.jiyun.classes.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {
    /*
     在你执行selectPage方法的时候，这个拦截器就会帮你拼接limit的语句，从而帮你实现分页
    */
    @Bean
    public MybatisPlusInterceptor createMybatisPlusInterceptor(){
        //1. 创建mybatis-plus拦截器
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        //2. 给mybatis-plus拦截器添加分页拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());

        //2.添加乐观锁拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //3,返回拦截器
        return mybatisPlusInterceptor;
    }

}